package cn.sciento.transfer.domain.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.choerodon.mybatis.annotation.ModifyAudit;
import io.choerodon.mybatis.annotation.VersionAudit;
import io.choerodon.mybatis.domain.AuditDomain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotBlank;
import cn.sciento.boot.platform.lov.annotation.LovValue;
import cn.sciento.starter.keyencrypt.core.Encrypt;
import org.springframework.util.Assert;

@ApiModel("数据核对批次行")
@VersionAudit
@ModifyAudit
@Table(name = "hdtt_data_chk_batch_line")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DataChkBatchLine extends AuditDomain {
  public static final String ENCRYPT_KEY = "cn.sciento.transfer.domain.entity.DataChkBatchLine";
  
  public static final String FIELD_DATA_CHK_BATCH_LINE_ID = "dataChkBatchLineId";
  
  public static final String FIELD_DATA_CHK_BATCH_ID = "dataChkBatchId";
  
  public static final String FIELD_SOURCE_SERVICE = "sourceService";
  
  public static final String FIELD_SOURCE_DS_ID = "sourceDsId";
  
  public static final String FIELD_SOURCE_DS = "sourceDs";
  
  public static final String FIELD_SOURCE_DB = "sourceDb";
  
  public static final String FIELD_SOURCE_TABLE = "sourceTable";
  
  public static final String FIELD_TARGET_SERVICE = "targetService";
  
  public static final String FIELD_TARGET_DS_ID = "targetDsId";
  
  public static final String FIELD_TARGET_DS = "targetDs";
  
  public static final String FIELD_TARGET_DB = "targetDb";
  
  public static final String FIELD_TARGET_TABLE = "targetTable";
  
  public static final String FIELD_TENANT_ID = "tenantId";
  
  public static final String FIELD_PROCESS_STATUS = "processStatus";
  
  public static final String FIELD_PROCESS_MSG = "processMsg";
  
  public static final String FIELD_PROCESS_TIME = "processTime";
  
  public static final String FIELD_REMARK = "remark";
  
  @Encrypt
  @ApiModelProperty("表ID，主键")
  @Id
  @GeneratedValue
  private Long dataChkBatchLineId;
  
  @Encrypt
  @ApiModelProperty("批次ID")
  @NotNull
  private Long dataChkBatchId;
  
  @ApiModelProperty("服务名")
  @NotBlank
  private String sourceService;
  
  @ApiModelProperty("数据源ID")
  private Long sourceDsId;
  
  @ApiModelProperty("数据源编码")
  private String sourceDs;
  
  @ApiModelProperty("DB编码")
  private String sourceDb;
  
  @ApiModelProperty("处理表，也是消息TOPIC")
  @NotBlank
  private String sourceTable;
  
  @ApiModelProperty("目标服务名")
  private String targetService;
  
  @ApiModelProperty("数据源ID")
  private Long targetDsId;
  
  @ApiModelProperty("数据源编码")
  private String targetDs;
  
  @ApiModelProperty("DB编码")
  private String targetDb;
  
  @ApiModelProperty("消费对应的表，默认跟消息生产表一样")
  private String targetTable;
  
  @ApiModelProperty("租户ID，按租户分发之用")
  private Long tenantId;
  
  @ApiModelProperty("处理状态，参考：HDTT.PROCESS_STATUS")
  @NotBlank
  @LovValue(lovCode = "HDTT.EVENT_PROCESS_STATUS", meaningField = "processStatusMeaning")
  private String processStatus;
  
  @ApiModelProperty("处理消息")
  private String processMsg;
  
  @ApiModelProperty("处理时间")
  private Date processTime;
  
  @ApiModelProperty("备注说明")
  private String remark;
  
  @Transient
  private String tenantName;
  
  @Transient
  @LovValue(lovCode = "HDTT.DATA_CHK_LEVEL", meaningField = "chkLevelMeaning")
  private String chkLevel;
  
  @Transient
  private String batchNum;
  
  @Transient
  private String chkLevelMeaning;
  
  @Transient
  private String processStatusMeaning;
  
  public void validParam() {
    Assert.notNull(getChkLevel(), "error.data_invalid");
    switch (getChkLevel()) {
      case "SOURCE_TABLE":
        Assert.notNull(getSourceService(), "error.data_invalid");
        Assert.notNull(getSourceTable(), "error.data_invalid");
        break;
      case "TARGET_TABLE":
        Assert.notNull(getTargetService(), "error.data_invalid");
        Assert.notNull(getTargetDb(), "error.data_invalid");
        Assert.notNull(getTargetDs(), "error.data_invalid");
        Assert.notNull(getTargetTable(), "error.data_invalid");
        break;
    } 
  }
  
  public Long getDataChkBatchLineId() {
    return this.dataChkBatchLineId;
  }
  
  public void setDataChkBatchLineId(Long dataChkBatchLineId) {
    this.dataChkBatchLineId = dataChkBatchLineId;
  }
  
  public Long getDataChkBatchId() {
    return this.dataChkBatchId;
  }
  
  public void setDataChkBatchId(Long dataChkBatchId) {
    this.dataChkBatchId = dataChkBatchId;
  }
  
  public String getSourceService() {
    return this.sourceService;
  }
  
  public void setSourceService(String sourceService) {
    this.sourceService = sourceService;
  }
  
  public Long getSourceDsId() {
    return this.sourceDsId;
  }
  
  public void setSourceDsId(Long sourceDsId) {
    this.sourceDsId = sourceDsId;
  }
  
  public String getSourceDs() {
    return this.sourceDs;
  }
  
  public void setSourceDs(String sourceDs) {
    this.sourceDs = sourceDs;
  }
  
  public String getSourceDb() {
    return this.sourceDb;
  }
  
  public void setSourceDb(String sourceDb) {
    this.sourceDb = sourceDb;
  }
  
  public String getSourceTable() {
    return this.sourceTable;
  }
  
  public void setSourceTable(String sourceTable) {
    this.sourceTable = sourceTable;
  }
  
  public String getTargetService() {
    return this.targetService;
  }
  
  public void setTargetService(String targetService) {
    this.targetService = targetService;
  }
  
  public Long getTargetDsId() {
    return this.targetDsId;
  }
  
  public void setTargetDsId(Long targetDsId) {
    this.targetDsId = targetDsId;
  }
  
  public String getTargetDs() {
    return this.targetDs;
  }
  
  public void setTargetDs(String targetDs) {
    this.targetDs = targetDs;
  }
  
  public String getTargetDb() {
    return this.targetDb;
  }
  
  public void setTargetDb(String targetDb) {
    this.targetDb = targetDb;
  }
  
  public String getTargetTable() {
    return this.targetTable;
  }
  
  public void setTargetTable(String targetTable) {
    this.targetTable = targetTable;
  }
  
  public Long getTenantId() {
    return this.tenantId;
  }
  
  public void setTenantId(Long tenantId) {
    this.tenantId = tenantId;
  }
  
  public String getProcessStatus() {
    return this.processStatus;
  }
  
  public void setProcessStatus(String processStatus) {
    this.processStatus = processStatus;
  }
  
  public String getProcessMsg() {
    return this.processMsg;
  }
  
  public void setProcessMsg(String processMsg) {
    this.processMsg = processMsg;
  }
  
  public Date getProcessTime() {
    return this.processTime;
  }
  
  public void setProcessTime(Date processTime) {
    this.processTime = processTime;
  }
  
  public String getRemark() {
    return this.remark;
  }
  
  public void setRemark(String remark) {
    this.remark = remark;
  }
  
  public String getTenantName() {
    return this.tenantName;
  }
  
  public void setTenantName(String tenantName) {
    this.tenantName = tenantName;
  }
  
  public String getChkLevel() {
    return this.chkLevel;
  }
  
  public void setChkLevel(String chkLevel) {
    this.chkLevel = chkLevel;
  }
  
  public String getBatchNum() {
    return this.batchNum;
  }
  
  public void setBatchNum(String batchNum) {
    this.batchNum = batchNum;
  }
  
  public String getProcessStatusMeaning() {
    return this.processStatusMeaning;
  }
  
  public void setProcessStatusMeaning(String processStatusMenaing) {
    this.processStatusMeaning = processStatusMenaing;
  }
  
  public String getChkLevelMeaning() {
    return this.chkLevelMeaning;
  }
  
  public void setChkLevelMeaning(String chkLevelMeaning) {
    this.chkLevelMeaning = chkLevelMeaning;
  }
}
